﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for CouponBus
/// </summary>
public class CouponBus
{
    CouponDAL cpDAL;
	public CouponBus()
	{
        cpDAL = new CouponDAL();
    }
    public bool InsertUpdate(Coupon cp)
    {
        if (cpDAL.InsertUpdateCoupon(cp)!=0) 
        {
            return true;
        }
        return false;
    }
    public DataTable getAllCoupon()
    {
        return cpDAL.GetAllCoupon();
    }
    public Coupon getCouponByID(int id)
    {
        Coupon cp = new Coupon();
        DataTable dt = cpDAL.getCouponByID(id);
        cp.Coupon_id = Convert.ToInt32(dt.Rows[0]["coupon_id"]);
        cp.Coupon_name = dt.Rows[0]["coupon_name"].ToString();
        cp.Coupon_des = dt.Rows[0]["coupon_des"].ToString();
        cp.Discount = Convert.ToInt32(dt.Rows[0]["discount"]);
        cp.Coupon_num = Convert.ToInt32(dt.Rows[0]["coupon_num"]);
        cp.Date_start = Convert.ToDateTime(dt.Rows[0]["date_start"]);
        cp.Date_end = Convert.ToDateTime(dt.Rows[0]["date_end"]);
        cp.Date_added = Convert.ToDateTime(dt.Rows[0]["date_added"]);
        return cp;
    }
    public Coupon getCouponByName(string name)
    {
        Coupon cp = new Coupon();
        DataTable dt = cpDAL.getCouponByName(name);
        cp.Coupon_id = Convert.ToInt32(dt.Rows[0]["coupon_id"]);
        cp.Coupon_name = dt.Rows[0]["coupon_name"].ToString();
        cp.Coupon_des = dt.Rows[0]["coupon_des"].ToString();
        cp.Discount = Convert.ToInt32(dt.Rows[0]["discount"]);
        cp.Coupon_num = Convert.ToInt32(dt.Rows[0]["coupon_num"]);
        cp.Date_start = Convert.ToDateTime(dt.Rows[0]["date_start"]);
        cp.Date_end = Convert.ToDateTime(dt.Rows[0]["date_end"]);
        cp.Date_added = Convert.ToDateTime(dt.Rows[0]["date_added"]);
        return cp;
    }
    public Coupon getCouponByDiscount(int discount)
    {
        Coupon cp = new Coupon();
        DataTable dt = cpDAL.getCouponByDiscount(discount);
        cp.Coupon_id = Convert.ToInt32(dt.Rows[0]["coupon_id"]);
        cp.Coupon_name = dt.Rows[0]["coupon_name"].ToString();
        cp.Coupon_des = dt.Rows[0]["coupon_des"].ToString();
        cp.Discount = Convert.ToInt32(dt.Rows[0]["discount"]);
        cp.Coupon_num = Convert.ToInt32(dt.Rows[0]["coupon_num"]);
        cp.Date_start = Convert.ToDateTime(dt.Rows[0]["date_start"]);
        cp.Date_end = Convert.ToDateTime(dt.Rows[0]["date_end"]);
        cp.Date_added = Convert.ToDateTime(dt.Rows[0]["date_added"]);
        return cp;
    }
    public Coupon getCouponByCouponNum(int value)
    {
        Coupon cp = new Coupon();
        DataTable dt = cpDAL.getCouponByCouponNum(value);
        cp.Coupon_id = Convert.ToInt32(dt.Rows[0]["coupon_id"]);
        cp.Coupon_name = dt.Rows[0]["coupon_name"].ToString();
        cp.Coupon_des = dt.Rows[0]["coupon_des"].ToString();
        cp.Discount = Convert.ToInt32(dt.Rows[0]["discount"]);
        cp.Coupon_num = Convert.ToInt32(dt.Rows[0]["coupon_num"]);
        cp.Date_start = Convert.ToDateTime(dt.Rows[0]["date_start"]);
        cp.Date_end = Convert.ToDateTime(dt.Rows[0]["date_end"]);
        cp.Date_added = Convert.ToDateTime(dt.Rows[0]["date_added"]);
        return cp;
    }
}